06. CODE: Write the A* Search Stub
Write the A* Search Stub
In this exercise, you will modify route_planner.h
, route_planner.cpp
, main.cpp
, and render.cpp
to add a method AStarSearch
, which will eventually become the search from start_node
to end_node
. In this exercise, you will only implement a basic version that returns a direct path between those two nodes. When you are done with this exercise, running the code should render a map with a direct path between the start and end nodes.
## To complete this exercise:
- Add a
AStarSearch
declaration to theRoutePlanner
class inroute_planner.h
. This method will be called frommain.cpp
, so it must be a public method.AStarSearch
will use thestart_node
andend_node
class variables, and it will modify them_Model
class variable, so it does not need any arguments, and should havevoid
return type. - In
route_planner.cpp
define theAStarSearch
method. The method should do the following:- Set the parent of
end_node
to thestart_node
. - Set
m_Model.path
to the result of callingConstructFinalPath
onend_node
.
- Set the parent of
- In
main.cpp
callAStarSearch
on theRoutePlanner
object. This should happen just after theRoutePlanner
object is defined, but before theRender render{model}
. - Also in
main.cpp
use theGetDistance()
method of theRoutePlanner
object to print the length of the path. - Uncomment the following lines in the
Render::Display
method inrender.cpp
. These lines will include the path in the rendered map:
// DrawPath(surface);
// DrawStartPosition(surface);
// DrawEndPosition(surface);
Workspace
This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity, so you may be able to download them there.
Workspace Information:
- Default file path:
- Workspace type: react
- Opened files (when workspace is loaded): n/a
-
userCode:
export CXX=g++-7
export CXXFLAGS=-std=c++17
cmake_tests() {
/usr/local/bin/cmake -DTESTING="AStarStub" "$1"
}
export -f cmake_tests
Solution
AStarStub